package com.yuqing.sentimentapp.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuqing.sentimentapp.R;

/**
 * Created by shenhe on 2019/4/19.
 */
public class TemplateTimeView extends LinearLayout {

    private TextView mTvTemplateTime;
    private ImageView mIvArrow;
    private boolean enabled = true;//默认view可用
    private LinearLayout rooter;
    private TemPlateTimeClickListener listener;

    public void setListener(TemPlateTimeClickListener listener) {
        this.listener = listener;
    }

    public TemplateTimeView(Context context) {
        super(context);
        initView(context);
    }

    public TemplateTimeView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public TemplateTimeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.view_template_time, this, true);
        rooter = ((LinearLayout) findViewById(R.id.layout_rooter));
        mTvTemplateTime = ((TextView) findViewById(R.id.tv_alarm_time));
        mIvArrow = ((ImageView) findViewById(R.id.iv_arrow));
    }

    public void setTemplateTime(String templateTime) {
        if (!TextUtils.isEmpty(templateTime)) {
            mTvTemplateTime.setText(templateTime);
        }
    }

    public String getTemplateTime() {
        return mTvTemplateTime.getText().toString().trim();
    }

    public void setArrowState(int resId) {
        mIvArrow.setImageResource(resId);
    }

    @Override
    public void setEnabled(boolean enabled) {
        if (enabled) {
            rooter.setClickable(true);
            rooter.setBackground(getResources().getDrawable(R.drawable.bg_layout_template_select_time_enable));
        } else {
            rooter.setClickable(false);
            rooter.setBackground(getResources().getDrawable(R.drawable.bg_layout_template_select_time_unenable));
        }
    }

    public interface TemPlateTimeClickListener {
        void onClick();
    }

}
